﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XChipTool.Enties
{
    public class SettingFile
    {
        //private string _FileName;
        /// <summary>
        /// 文件路径
        /// </summary>
        public string FilePath { get; set; }
        /// <summary>
        /// 文件名称
        /// </summary>
        public string FileName { get; set; }
        /// <summary>
        /// 制式名称
        /// </summary>
        public string StandardName
        {
            get
            {
                if (FileName.ToLower().Contains("ahd"))
                {
                    return "AHD";
                }
                else if (FileName.ToLower().Contains("thd"))
                {
                    return "THD";
                }
                else if (FileName.ToLower().Contains("chd"))
                {
                    return "CHD";
                }
                else if (FileName.ToLower().Contains("cvbs"))
                {
                    return "CVBS";
                }
                else
                {
                    return null;
                }

            } }
        /// <summary>
        /// 时序名称
        /// </summary>
        public string TimingName
        {
            get
            {
                var iarr = FileName.Split(new char[1] { '_' });
                string FileNamei = "";
                
                for (int i = 0; i < iarr.Length; i++)
                {
                    if (!iarr[i].ToLower().Contains("scale"))
                    {
                        FileNamei += iarr[i].ToString() + "_";
                    }
                }
                if (FileNamei.ToLower().Contains("1080p") && FileNamei.ToLower().Contains("30fps"))
                {
                    return "1080p30";
                }
                else if (FileNamei.ToLower().Contains("1080p") && FileNamei.ToLower().Contains("25fps"))
                {
                    return "1080p25";
                }
                else if (FileNamei.ToLower().Contains("720p") && FileNamei.ToLower().Contains("30fps"))
                {
                    return "720p30";
                }
                else if (FileNamei.ToLower().Contains("720p") && FileNamei.ToLower().Contains("25fps"))
                {
                    return "720p25";
                }
                else if (FileNamei.ToLower().Contains("960h") && FileNamei.ToLower().Contains("60fps"))
                {
                    return "960h60";
                }
                else if (FileNamei.ToLower().Contains("960h") && FileNamei.ToLower().Contains("50fps"))
                {
                    return "960h50";
                }
                else if (FileNamei.ToLower().Contains("5m") && FileNamei.ToLower().Contains("20fps"))
                {
                    return "5M20";
                }
                else if (FileNamei.ToLower().Contains("5m") && FileNamei.ToLower().Contains("12fps"))
                {
                    return "5M12";
                }
                else if (FileNamei.ToLower().Contains("4m") && FileNamei.ToLower().Contains("30fps"))
                {
                    return "4M30";
                }
                else if (FileNamei.ToLower().Contains("4m") && FileNamei.ToLower().Contains("25fps"))
                {
                    return "4M25";
                }
                else
                {
                    return null;
                }

            }
        }
        /// <summary>
        /// setting分区X
        /// </summary>
        public string SetPartitions
        {
            get
            {
                if (FileName.ToLower().Contains("ahd") || FileName.ToLower().Contains("thd") || FileName.ToLower().Contains("chd") || FileName.ToLower().Contains("cvbs"))
                {
                    //var iarr = FileName.Split(new char[1] { '_' });
                    //return iarr[3].ToString().Replace("setting","");
                    return null;

                }
                else
                {
                    var iarr = FileName.Split(new char[1] { '_' });
                    return iarr[0].ToString().Replace("setting", "");
                }

            }
        }
        /// <summary>
        /// setting套数{X}
        /// </summary>
        public string SetNumber
        {
            get
            {
                if (FileName.ToLower().Contains("ahd") || FileName.ToLower().Contains("thd") || FileName.ToLower().Contains("chd") || FileName.ToLower().Contains("cvbs"))
                {
                    //var iarr = FileName.Split(new char[1] { '_' });
                    //return iarr[4].ToString().Replace("[","").Replace("]","");
                    return null;

                }
                else
                {
                    var iarr = FileName.Split(new char[1] { '_' });
                    return iarr[1].ToString().Replace("[", "").Replace("]", "");
                }

           }
       }


        public int Tag
        {
            get {
                try
                {
                    return int.Parse(SetPartitions) * 32 + int.Parse(SetNumber) + 1;
                }
                catch
                {
                    return -1;
                }
                
            }
        }


        /// <summary>
        /// 序号
        /// </summary>
        public string SettingNo { get; set; }
        /// <summary>
        /// 传输
        /// </summary>
        public string TransferName { get; set; }
        /// <summary>
        /// 视频
        /// </summary>
        public string VideoName { get; set; }


        /// <summary>
        /// 传输
        /// </summary>
        public string TransferHex { get; set; }
        /// <summary>
        /// 视频
        /// </summary>
        public string VideoHex { get; set; }

        /// <summary>
        /// 提示
        /// </summary>
        public string Tips {
            get {
                if (TransferName !=null)
                {
                    return TransferName + VideoName + "_" + TipsSettingNo;
                }
                else
                {
                    return TransferName + VideoName ;
                }
            }
           
        }
        public string TipsSettingNo { get; set; }
        /// <summary>
        /// 菜单数量  用于计算菜单结构长度 计算公式 844*4* 菜单数量
        /// </summary>
        public int MenuNo { get; set; }
        /// <summary>
        /// 语言数量 
        /// </summary>
        public int LanguageNo { get; set; }
        /// <summary>
        /// 是否勾选版本号
        /// </summary>
        public bool IsVersion { get; set; }

        /// <summary>
        /// 存放指示
        /// </summary>
        public string Mode { get; set; }

        /// <summary>
        /// 模式
        /// </summary>
        public int patternNo { get; set; }
        /// <summary>
        /// 制式
        /// </summary>
        public int formatNo { get; set; }

        public List<SettingFile> data { get; set; }

        public List<SettingFile> comData { get; set; }
        /// <summary>
        ///是否存在制式
        /// </summary>
        public bool Standarddisplay { get; set; }

        /// <summary>
        /// 地址    需要添加 0xfffd,0x20,0xfffe,0x00, 为头文件
        /// </summary>
        public uint hexAddr { get; set; }
        /// <summary>
        /// 视频格式的值
        /// </summary>

        public uint hexVal { get; set; }

        public string hexNote { get; set; }
        /// <summary>
        /// 软件要配置的寄存器数组
        /// </summary>
        public string HexOut { get { return $"0x{hexAddr.ToString("X").PadLeft(4,'0')},0x{hexVal.ToString("X").PadLeft(2,'0')},//{hexNote}"; } }
    }


    public class SettingTo151_Help {

        /// <summary>
        /// 全局是否开启EEPROW值  默认值位false  
        /// </summary>
        public static bool isEepRom = false;
        /// <summary>
        /// 芯片为true  fpj为false
        /// </summary>
        public static bool isXChip = true;

        private static List<SettingFile> setTips151;

        public static void setTips151clear()
        {
            setTips151 = null; 
        }
        public static List<SettingFile> SetTips151
        {
            get
            {
                if (null == setTips151)
                {
                    setTips151 = new List<SettingFile>();
                    for (int i = 0; i < 129; i++)
                    {

                        setTips151.Add(new SettingFile());
                    }
                }
                return setTips151;
            }

            set
            {
                setTips151 = value;
            }
        }

        public static void ClearSetTips151() {
            setTips151 = new List<SettingFile>();
            for (int i = 0; i < 129; i++)
            {

                setTips151.Add(new SettingFile());
            }
        }

       
    }


    public class SettingToTve151
    {
        /// <summary>
        /// 全局是否开启EEPROW值  默认值位false  
        /// </summary>
        public static bool isEepRom = false;
        /// <summary>
        /// 芯片为true  fpj为false
        /// </summary>
        public static bool isXChip = true;

        private static List<SettingFileNew> setTips151;
        public static void setTips151clear()
        {
            setTips151 = new List<SettingFileNew>();
            for (int i = 0; i < 48; i++)
            {
                setTips151.Add(new SettingFileNew());
            }
            
        }

        public static List<SettingFileNew> SetTips151
        {
            get
            {
                if (null == setTips151)
                {
                    setTips151 = new List<SettingFileNew>();
                    for (int i = 0; i < 48; i++)
                    {
                        setTips151.Add(new SettingFileNew());
                    }
                }
                return setTips151;
            }

            set
            {
                setTips151 = value;
            }
        }


        public static void ClearTve151()
        {
            setTips151 = null;
        }
    }


    public class LoadSetting {

       
       

        /// <summary>
        /// 地址
        /// </summary>
        public uint addr { get; set; }
        /// <summary>
        /// 值
        /// </summary>
        public uint val { get; set; }
        /// <summary>
        /// 文件名称
        /// </summary>
        public string FileName { get; set; }
        /// <summary>
        /// 输出文字
        /// </summary>
        public string note { get
            {
                return $"0x{addr.ToString("X4")},0x{val.ToString("X2")},";
            }
        }



    }



  
}
